local redis = require 'resty.redis'
local red = redis:new()

red:set_timeout(1000)

local ok, err = red:connect('101.132.36.174', 6379)

if not ok then
  ngx.say('failed to connect: ', err)
end

local count
count, err = red:get_reused_times() -- 连接首次需要认证,首次count为0,表示没有用过,连接池的连接count大于0
if 0 == count then 
  ok, err = red:auth('rainhowchan') -- redis认证
  if not ok then
    ngx.say("failed to auth: ",err) 
  end
elseif err then
  ngx.say("failed to get reused times: ",err)
  return
end

local res, err = red:get("binance.CDTUSDT")
if not res then
  ngx.say('failed to get CDTUSDT: ',err)
  return
end

if ngx.null == res then
  ngx.say('CDTUSDT not found')
  return
end

ngx.say('binance.CDTUSDT: ',res)



local ok, err = red:set_keepalive(10000, 100)

if not ok then
  ngx.say('failed to set keepalive: ', err)
  return
end